package com.example.testapplication;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class SecondDemo extends AppCompatActivity {
    private EditText et_second_message;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second2);

        et_second_message = (EditText) findViewById(R.id.et_second_message);

        // 得到传递过来的值
        Intent intent = getIntent();
        // 通过intent读取数据
        String message = intent.getStringExtra("MESSAGE");
        // 显示到EditText
        et_second_message.setText(message);
        Log.d("Tag", "onActivityResult: " + message);
    }

    // 按钮事件
    public void back1(View v){
        // 关闭当前界面
        finish();
    }

    public void back2(View v){
        // 保存一个结果
        int resultCode = 3;
        Intent data = new Intent();
        String result = et_second_message.getText().toString();
        data.putExtra("RESULT",result);
        // 设置结果
        setResult(resultCode,data);
        // 关闭当前界面
        finish();
    }
}
